package Practice;

import java.util.Scanner;

public class Serpentine {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] a =new int[n][n];
        int op = 1;
        int left = 0, right = n - 1, top = 0, bottom = n - 1;
        while (op<=n*n){
            // 从左到右
            for (int i = left; i <= right; i++) {
                a[top][i] = op;
                op++;
            }
            top++;// 上边界下移

            // 从上到下
            for (int i = top; i <= bottom; i++) {
                a[i][right] = op;
                op++;
            }
            right--;// 右边界左移

            // 从右到左
            if (top <= bottom) { // 检查是否越界
                for (int i = right; i >= left; i--) {
                    a[bottom][i] = op;
                    op++;
                }
                bottom--; // 下边界上移
            }

            // 从下到上
            if (left <= right) { // 检查是否越界
                for (int i = bottom; i >= top; i--) {
                    a[i][left] = op;
                    op++;
                }
                left++; // 左边界右移
            }
        }
        for (int i = 0; i < n; i++) {
            for (int p = 0; p < n; p++) {
                System.out.printf("%3d", a[i][p]);
            }
            System.out.println();
        }
    }
}
